<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity5">
<head th:replace="~{segmentation/_right_bottom_header::_header_common(~{::title},~{::link},~{::style})}">
    <meta charset="utf-8">
    <title>用户个人信息编辑</title>
    <link>
    <style type="text/css"></style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>用户个人信息编辑</legend>
        </fieldset>
        <form class="layui-form" id="userFormEdit" action="">
            <input type="hidden" id="id" name="id" th:value="${p.id}"/>
            <div class="layui-form-item" pane="">
                <label class="layui-form-label">帐号</label>
                <div class="layui-input-block">
                    <span class="view-span" sec:authentication="name"></span>
                </div>
            </div>
            <div class="layui-form-item" pane="">
                <label class="layui-form-label"><span class="required-red">*</span>姓名</label>
                <div class="layui-input-block">
                    <input type="text" name="name" lay-verify="required"
                           lay-verType="tips"
                           th:value="${p.name}"
                           placeholder="请输入电话" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span class="required-red">*</span>电话</label>
                <div class="layui-input-block">
                    <input type="text" name="phone" lay-verify="required|phone|telphone"
                           lay-verType="tips"
                           th:value="${p.phone}"
                           placeholder="请输入电话" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span class="required-red">*</span>邮箱</label>
                <div class="layui-input-block">
                    <input type="text" name="email" lay-verify="required|email|myEmail"
                           lay-verType="tips"
                           th:value="${p.email}"
                           placeholder="请输入邮箱" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item custom-text-align">
                <a class="layui-btn" lay-submit="" lay-filter="userFormEditInfoSubmit">保存</a>
            </div>
        </form>
    </div>
</div>

<div th:replace="~{segmentation/_tail::_tail_common}"></div>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script th:inline="javascript">
    layui.use(['form', 'common'], function () {
        var form = layui.form,
            layer = layui.layer,
            common = layui.common;

        //自定义验证规则
        form.verify({
            name: function (value) {
                if (value.length > 20) {
                    return '姓名最多20个字符';
                }
            },
            telphone: function (value) {
                if (value.length > 20) {
                    return '电话最多20个字符';
                }
            },
            myEmail: function (value) {
                if (value.length > 32) {
                    return '邮箱最多32个字符';
                }
            },
        });

        //监听提交
        form.on('submit(userFormEditInfoSubmit)', function (data) {
            $.ajax({
                type: 'POST',
                url: '/personal/center/edit/info',
                data: data.field,
                dataType: 'json',
                success: function (data) {
                    if (data.code == Result.SUCCESS) {
                        layer.msg('成功!', {
                            icon: 1,
                            shade: [0.3, '#f5f5f5'],
                            time: 1500
                        }, function () {
                            common.closeThisTabs("/personal/center/reset/info");
                        });
                    } else {
                        layer.msg(data.msg, {
                            icon: 2,
                            time: 3000
                        });
                    }
                },
                error: function (data) {
                }
            });
            return false;//返回false防止重复提交
        });
    });
</script>

</body>
</html>